var username  = '<? echo $username;?>';
var password  = '<? echo $password;?>';
var user_vip  = '<? echo $user_vip;?>';
var cion  = '<? echo $cion;?>';

//查找聊天记录
 var oBtn = document.getElementById('chat_log_btn');
     oBtn.onclick = function(){
     window.open("/log_chat.php?username=<? echo $username;?>&password=<? echo $password;?>");                 
};

//抢红包
function get_redball_btn(){
	 $.post("/redball/index.php", { username: username,password: password,cion: cion},
   function(data){
	//返回值
    layer.alert(data);
    });
}
//info
 var oBtn = document.getElementById('info_btn');
     oBtn.onclick = function(){
		 if(username!='guest'){
			 layer.open({
  type: 2,
  title: '个人信息',
  shadeClose: true,
  shade: 0.8,
  area: ['350px', '180px'],
  content: '/info.php?username=<? echo $username;?>&password=<? echo $password;?>' //iframe的url
}); 
		  }else{
			layer.msg('试玩账户无法使用聊天室请注册');
		  }

};

var oBtn = document.getElementById('face_btn');
oBtn.onclick = function(){
layer.open({
type: 2,
title: '发送表情',
shadeClose: true,
shade: 0.8,
area: ['300px', '250'],
content: '/face.php?username=<? echo $username;?>&password=<? echo $password;?>&vip=<? echo $user_vip;?>&cion=<? echo $cion;?>' //iframe的url
}); 
};

var oBtn = document.getElementById('images_btn');
oBtn.onclick = function(){
layer.open({
type: 2,
title: '发送图片',
shadeClose: true,
shade: 0.8,
area: ['300px', '180'],
content: '/file.php?username=<? echo $username;?>&password=<? echo $password;?>&vip=<? echo $user_vip;?>&cion=<? echo $cion;?>' //iframe的url
}); 
};
function sends(){
//获取内容值
var sendvalue = document.getElementById('send_value').value;
//判断是否为空
if(sendvalue == ''){
layer.msg('发送的信息不能为空');
return false;
}
document.getElementById('send_value').value = '';
//OK后发送post
$.post("send.php", { sendvalue: sendvalue,username: username,password: password,user_vip: user_vip,cion: cion},
function(data){
//返回值
layer.msg(data);
});
}

//回车键发送
document.onkeydown=function(){
  if (event.keyCode == 13){
      if(username!='guest'){
         sends(); 
      }else{
        layer.msg('试玩账户无法使用聊天室请注册');
      }
      
       }
   }
//点击按钮发送
var oBtn = document.getElementById('send_button');
oBtn.onclick = function(){
    if(username!='guest'){
         sends(); 
      }else{
        layer.msg('试玩账户无法使用聊天室请注册');
      }
};

var xmlobj; 
    function createXMLHttpRequest(){ 
      if(window.ActiveXObject){ 
        xmlobj=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      else if(window.XMLHttpRequest){ 
        xmlobj=new XMLHttpRequest(); 
      } 
    } 
    function Autofresh(){ 
      createXMLHttpRequest();     
	  //get已经获取到的用户名
      xmlobj.open("GET","center.php?username=<? echo $username;?>&password=<? echo $password;?>&cion=<?echo $cion;?>",true); 
      xmlobj.onreadystatechange=doAjax; 
      xmlobj.send("r="+Math.random());//使用随机数处理缓存
	} 
    function doAjax(){ 
      if(xmlobj.readyState==4 && xmlobj.status==200){ 
        var time_span=document.getElementById('center'); 
        time_span.innerHTML=xmlobj.responseText; 
	    setTimeout("Autofresh()",500); 
      } 
    } 
  </script>

<? if($admin == '1'){ ?>

<script>
 var oBtn = document.getElementById('send_ball_btn');
     oBtn.onclick = function(){
layer.open({
  type: 2,
  title: '发送红包',
  shadeClose: true,
  shade: 0.8,
  area: ['300px', '200px'],
  content: '/redball/send_ball.php?username=<? echo $username;?>&password=<? echo $password;?>' //iframe的url
}); 
};
</script>

<? } ?>